Skip to content

GitLabRunner安装部署

实战:GitLabRunner安装部署-2023.4.26(安装成功)

image-20230426063250435

目录

[toc]

实验环境

bash
gitlab/gitlab-ce:15.0.3-ce.0gitlab-runner-15.0.1-1.x86_64.rpm

实验软件

链接:https:--2023-04-2606:42:18--https:Resolvingmirrors.tuna.tsinghua.edu.cn(mirrors.tuna.tsinghua.edu.cn)... 101.6.15.130,2402:f000:1:400::2Connectingtomirrors.tuna.tsinghua.edu.cn(mirrors.tuna.tsinghua.edu.cn)|101.6.15.130|:443...connected.WARNING:cannotverifymirrors.tuna.tsinghua.edu.cn's certificate,issued by ‘/C=US/O=Let'sEncrypt/CN=R3’:Issuedcertificatehasexpired.HTTPrequestsent,awaitingresponse...200OKLength:434734559(415M) [application/x-redhat-package-manager]Savingto:‘gitlab-runner-15.0.1-1.x86_64.rpm’100%[================================================================================================================================================================>]434,734,55914.3MB/sin33s2023-04-2606:42:52(12.4 MB/s) - ‘gitlab-runner-15.0.1-1.x86_64.rpm’ saved [434734559/434734559][root@Devops6 ~]#ll -h gitlab-runner-15.0.1-1.x86_64.rpm -rw-r--r--1rootroot415MJul212022gitlab-runner-15.0.1-1.x86_64.rpm

2、安装gitlab-runner rpm包

3、验证

2、注册Runner

1、获取GitLab地址和Runner 注册token

  • 本次注册平台级别runner:

点击Menu/Admin/Runners

image-20220505105632269

image-20220505105641693

保存下上面这个token:

osNyPCDx47f52iD4Hh5F

2、运行注册命令

  • 开始交互式注册
bash
[root@Devops6 ~]#gitlab-runner registerRuntimeplatformarch=amd64os=linuxpid=53427revision=7674edc7version=15.0.1Runninginsystem-mode.EntertheGitLabinstanceURL(for example,https:http:Entertheregistrationtoken:osNyPCDx47f52iD4Hh5FEnteradescriptionfortherunner:[Devops6]:build01Entertagsfortherunner(comma-separated):build,go,mavenEnteroptionalmaintenancenotefortherunner:Registeringrunner...succeededrunner=osNyPCDxEnteranexecutor:parallels,shell,docker+machine,docker-ssh+machine,kubernetes,custom,docker,docker-ssh,ssh,virtualbox:shellRunnerregisteredsuccessfully.Feelfreetostartit,butifit's running already the config should be automatically reloaded!

image-20230426065725839

说明:默认注册采用的交互式,需要交互填写信息。

bash
[root@zeyang-nuc-service gitlab-runner]# gitlab-runner registerRuntimeplatformarch=amd64os=linuxpid=40969revision=f188edd7version=14.9.1Runninginsystem-mode.## 输入GitLab实例的URLEntertheGitLabinstanceURL(for example,https:http:## 输入Runner注册TokenEntertheregistrationtoken:m5ucdGk2_uPJ2K9BP8-d## 填写该注册Runner的描述信息Enteradescriptionfortherunner:[zeyang-nuc-service]:build runner## 为该Runner配置一个标签(后续作业可以通过tag指定在哪个runner上面运行构建)Entertagsfortherunner(comma-separated):build,go,mavenEnteroptionalmaintenancenotefortherunner:Registeringrunner...succeededrunner=m5ucdGk2## 为Runner选择一个执行器Enteranexecutor:docker,parallels,ssh,docker+machine,docker-ssh+machine,custom,docker-ssh,shell,virtualbox,kubernetes:shellRunnerregisteredsuccessfully.Feelfreetostartit,butifit's running already the config should be automatically reloaded!
  • 本地查看runner信息
bash
[root@Devops6 ~]#gitlab-runner listRuntimeplatformarch=amd64os=linuxpid=53774revision=7674edc7version=15.0.1ListingconfiguredrunnersConfigFile=/etc/gitlab-runner/config.tomlbuild01Executor=shellToken=PzMYek9JphRmM5Fo5qKoURL=http:[root@Devops6 ~]#gitlab-runner verifyRuntimeplatformarch=amd64os=linuxpid=53789revision=7674edc7version=15.0.1Runninginsystem-mode.Verifyingrunner...isaliverunner=PzMYek9J

image-20230426065933483

  • 当然也可以使用非交互模式来注册:
bash
gitlab-runnerregister\--non-interactive\--url"http:--registration-token"m5ucdGk2_uPJ2K9BP8-d"\--executor"shell"\--description"buildrunner"\--tag-list"build,k8s,go"\--run-untagged="true"\--locked="false"\--access-level="not_protected"#本次测试虚机代码gitlab-runnerregister\--non-interactive\--url"http:--registration-token"osNyPCDx47f52iD4Hh5F"\--executor"shell"\--description"buildrunner"\--tag-list"build,mvn,go"\--run-untagged="true"\--locked="false"\--access-level="not_protected"

3、刷新GitLab管理页面

image-20230426065933483

3、配置Runner

  • 通过Gitlab后台可以看下runner的配置:

image-20230426070209955

image-20230426070221000

  • gitlab-runner配置文件 (改完配置文件,它会自动生效的。)
bash
[root@Devops6 ~]#cat /etc/gitlab-runner/config.toml concurrent=1check_interval=0[session_server]session_timeout=1800[[runners]]name="build01"url="http:token="PzMYek9JphRmM5Fo5qKo"executor="shell"[runners.custom_build_dir][runners.cache][runners.cache.s3][runners.cache.gcs][runners.cache.azure]

说明:

bash
concurrent=1## 可并行运行作业的数量, 0表示不限制;check_interval=0## 检查新作业的时间间隔, 0表示默认 3秒;[session_server]	## 允许用户与作业进行交互,例如web终端;session_timeout=1800[[runners]]name="my first runner"## Runner名称;url="http:token="z6QEqyGpDrvzNgfxLiVh"## Runner token;executor="shell"## Runner的执行器;[runners.custom_build_dir]	## 允许用户为作业定义自定义构建目录;[runners.cache]	## 分布式缓存目录;[runners.cache.s3][runners.cache.gcs][runners.cache.azure]

高级配置参考: https:gitlab-runnerlist#此命令列出了保存在配置文件中的所有运行程序gitlab-runnerverify#此命令检查注册的runner是否可以连接,但不验证GitLab服务是否正在使用runner。 --delete 删除gitlab-runnerunregister#该命令使用GitLab取消已注册的runner。#使用令牌注销gitlab-runnerunregister--urlhttp:#使用名称注销(同名删除第一个)gitlab-runnerunregister--nametest-runner#注销所有gitlab-runnerunregister--all-runners

FAQ

升级完git版本后,gitlabrunner会被删除的

  • 升级完git后,gitlab-runner没掉了,再次安装gitlab-runner时报错

image-20230510075035521

  • 那就使用yum来安装依赖包,就可以解决问题了
bash
[root@Devops6 ~]#yum install -y gitlab-runner-15.0.1-1.x86_64.rpm

image-20230510075300644

image-20230510075319476

centos8安装时报错

自己是在centos7上测试的,这里先做记录。

  • 报错现象

image-20230426071902663

  • 解决办法

image-20230426071917534

注意:runner的Run untagged jobs配置

默认是勾选了的。

image-20230516072615230

image-20230516072626943

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!

🍀 微信二维码 x2675263825 (舍得), qq:2675263825。

image-20230107215114763

🍀 微信公众号 《云原生架构师实战》

image-20230107215126971

🍀 语雀

https:

版权:此文章版权归 One 所有,如有转载,请注明出处!

链接:可点击右上角分享此页面复制文章链接

上次更新时间:

最近更新